/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.view;

import java.awt.event.ActionEvent;
import java.util.Vector;

import javax.swing.JComboBox;

import soccerscope.model.ScenePlayModeList;
import soccerscope.model.ScenePlayModeListItem;
import soccerscope.model.ScenePlayModeListObserver;
import soccerscope.model.SceneSet;
import soccerscope.model.WorldModel;

public class ChronologicScenePlayModeJumper extends AbstractSceneJumper 
        implements ScenePlayModeListObserver {

    private static final long serialVersionUID = 1952046359577513197L;

    private JComboBox box;
    
    /**
     * Creates a new SceneJumper to jump from a scene in a play mode to another
     * scene of another play mode.
     * 
     * @param scenePlayer the scene player to set the new scene.
     */
    public ChronologicScenePlayModeJumper(ScenePlayer scenePlayer) {
        super(scenePlayer);
        SceneSet sceneSet = WorldModel.getSceneSet();
        ScenePlayModeList pml = sceneSet.getScenePlayModeList();
        
        box = new JComboBox(new Vector(pml.getAllScenePlayModes()));
        add(box);
        pml.addObserver(this);
    }

    /**
     * This method is called, when a the play mode has changed
     * @param item the scene number and the new play mode in one object
     */
    public void newScenePlayModeAdded(ScenePlayModeListItem item) {
        box.addItem(item);
    }

    /**
     * Thie method is called, when the whole list has changed, e.g. after loading
     *
     */
    public void allChanged() {
        SceneSet sceneSet = WorldModel.getSceneSet();
        ScenePlayModeList pml = sceneSet.getScenePlayModeList();
        
        remove(box);
        box = new JComboBox(new Vector(pml.getAllScenePlayModes()));
        add(box);
        box.setVisible(true);
    }


    /**
     * Jumps to the selected scene.
     */
    public void actionPerformed(ActionEvent arg0) {
        jumpToScene(((ScenePlayModeListItem) box.getSelectedItem()).getScene());
    }

}
